﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using DBUtility;
using System.Data;
using TTSIDAL;
using TTSModel;
namespace TTSDAL
{
    public class CPKParameterValue : BaseRepository<CPKParameterValueInfo>, ICPKParameterValue
    {
          #region 静态变量定义

        private const string PARMStartSN = "@StartSN";
        private const string PARMEndSN = "@EndSN";
        private const string PARM_ParamaterName = "@ParamaterName";
        private const string PARM_TestType = "@TestType";
        #endregion

        #region 数据检索部分
        public IList<CPKParameterValueInfo> LoadEntities()
        {
            return null;
        }

        public CPKParameterValueInfo LoadEntity<T1>(T1 id)
        {          
            return null;
        }

        public CPKParameterValueInfo CPKParameterValue_GetbySNRange(string startSN, string endSN, string parameterName, string testType)
        {
            SqlParameter[] parms = GetParameters();
            parms[0].Value = startSN;
            parms[1].Value = endSN;
            parms[2].Value = parameterName;
            parms[3].Value = testType;
            return ExcuteSqlToGetEntity("T0001996_CPKParaValueSNRange", parms);
        }

        public CPKParameterValueInfo CPKParameterValue_GetbySNRange(string spname, string startSN, string endSN, string parameterName, string testType)
        {
            SqlParameter[] parms = GetParameters();
            parms[0].Value = startSN;
            parms[1].Value = endSN;
            parms[2].Value = parameterName;
            parms[3].Value = testType;
            return ExcuteSqlToGetEntity(spname, parms);
        }
        #endregion

        #region 重写基类方法
        public override CPKParameterValueInfo GetEntityRecord(SqlDataReader rdr)
        {
            CPKParameterValueInfo entity = new CPKParameterValueInfo()
            {
                Mean = Convert.IsDBNull(rdr["Mean"]) ? "NULL" : rdr.GetDecimal(0).ToString("0.00"),
                StandardDeviation = Convert.IsDBNull(rdr["Stev"]) ? "NULL" : rdr.GetDecimal(1).ToString("0.00"),
                USL = Convert.IsDBNull(rdr["USL"]) ? "NULL" : rdr.GetDecimal(2).ToString("0.00"),
                PositiveThreeSD = Convert.IsDBNull(rdr["PTStev"]) ? "NULL" : rdr.GetDecimal(3).ToString("0.00"),
                NegativeThreeSD = Convert.IsDBNull(rdr["NTStev"]) ? "NULL" : rdr.GetDecimal(4).ToString("0.00"),
                LSL = Convert.IsDBNull(rdr["LSL"]) ? "NULL" : rdr.GetDecimal(5).ToString("0.00"),
                TotalCount = Convert.IsDBNull(rdr["TotalCount"]) ? "NULL" : rdr.GetInt32(6).ToString(),
                FailCount = Convert.IsDBNull(rdr["FailCount"]) ? "NULL" : rdr.GetInt32(7).ToString(),
                CP = Convert.IsDBNull(rdr["CP"]) ? "NULL" : rdr.GetDecimal(8).ToString("0.00"),
                CPL = Convert.IsDBNull(rdr["CPL"]) ? "NULL" : rdr.GetDecimal(9).ToString("0.00"),
                CPU = Convert.IsDBNull(rdr["CPU"]) ? "NULL" : rdr.GetDecimal(10).ToString("0.00"),
                CPK = Convert.IsDBNull(rdr["CPK"]) ? "NULL" : rdr.GetDecimal(11).ToString(),
                XAxisMinorStep =(double)rdr.GetDecimal(12),
                XAxisMajorStep = (double)rdr.GetDecimal(13),
                TitleXAxis = Convert.IsDBNull(rdr["XAxisMajortitle"]) ? "NULL" : rdr.GetString(14),
            };
            return entity;
        }
       
        public override CPKParameterValueInfo GetEntityRecord()
        {
            CPKParameterValueInfo entity = new CPKParameterValueInfo();
            return entity;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter parm = new SqlParameter(PARM_ParamaterName, SqlDbType.NVarChar, 150);
            return parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = new SqlParameter[]
            {              
                new SqlParameter(PARMStartSN,SqlDbType.NVarChar,10),
                new SqlParameter(PARMEndSN,SqlDbType.NVarChar,10),
                new SqlParameter(PARM_ParamaterName,SqlDbType.NVarChar,150),
                new SqlParameter(PARM_TestType,SqlDbType.NVarChar,10),
            };
            return parms;
        }

        public override void SetParameters(CPKParameterValueInfo Entity, params SqlParameter[] Parms)
        {
            Parms[0].Value = Entity.CP;
            Parms[1].Value = Entity.CPK;
           
        }
        #endregion
    }
   
}
